package com.supermap.originTest;


import com.supermap.data.*;
import com.supermap.data.conversion.DataImport;
import com.supermap.data.conversion.ImportMode;
import com.supermap.data.conversion.ImportResult;
import com.supermap.data.conversion.ImportSettingCSV;

import java.util.Arrays;


public class TestImportTxt {

	/**
	 * 程序入口点
	 * The entrance of the programme.
	 */
	public static void main(String[] args) {


		Workspace workspace = new Workspace();
		WorkspaceConnectionInfo conInfo = new WorkspaceConnectionInfo(
				"E:\\MapData\\202404\\test\\WorkSpace.smwu");

		conInfo.setType(WorkspaceType.SMWU);
		workspace.open(conInfo);
		Datasource datasource = workspace.getDatasources().get(0);

		String filePath = "D:\\20240628相对航行基准面数据.txt";
		ImportSettingCSV importSetting = new ImportSettingCSV();
		importSetting.setSourceFilePath(filePath);
		importSetting.setSourceFileCharset(Charset.UTF8);

		importSetting.setTargetDatasource(datasource);
		importSetting.setTargetDatasetName("test");
		importSetting.setImportMode(ImportMode.OVERWRITE);
		PrjCoordSys prjCoordSys = new PrjCoordSys();
		prjCoordSys.setEPSGCode(4547);
		prjCoordSys.setCoordUnit(Unit.METER);
//		importSetting.setTargetPrjCoordSys(prjCoordSys);
		importSetting.setSeparator(",");
		importSetting.setFirstRowIsField(false);
//		importSetting.setFieldsAsPoint(new String[]{"col1","col2"});
		importSetting.setIndexsAsPoint(new int[]{1,2});

		DataImport dataImport = new DataImport();

		dataImport.getImportSettings().add(importSetting);
		ImportResult importResult = dataImport.run();
		System.out.println(Arrays.stream(importResult.getFailedSettings()).count());



	}

}

